/*
 * Ant Group
 * Copyright (c) 2004-2024 All Rights Reserved.
 */
package com.alipay.zmdepositdemo.controller;

import com.alipay.zmdepositdemo.model.OpenResponse;
import com.alipay.zmdepositdemo.service.manage.DepositOrderManageService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 同步服务订单信息
 *
 * @author zhangjian
 * @version DepositOrderSyncController.java, v 0.1 2024年07月04日 14:29 zhangjian
 */

@Api(tags = "同步服务订单信息")
@ApiSupport(order = 6)
@RestController
@RequestMapping(value = "/sync-deposit-order")
public class DepositOrderSyncController {

    @Autowired
    private DepositOrderManageService depositOrderManageService;

    /**
     * 同步免押订单信息
     *
     * @see <a href="https://opendocs.alipay.com/open/98f05688_alipay.trade.orderinfo.sync?scene=common&pathHash=d62cb952">...</a>
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "支付宝订单信息同步接口")
    @GetMapping(value = "/sync")
    public OpenResponse<Boolean> syncOrder(
            @ApiParam(value = "支付宝交易号", defaultValue = "2014112611001004680073956707") @RequestParam(required = true) String tradeNo,
            @ApiParam(value = "退款请求号", defaultValue = "outRefundRequestNoHZ01RF001") @RequestParam(required = true)
            String outRequestNo,
            @ApiParam(value = "业务类型", defaultValue = "CREDIT_AUTH") @RequestParam(required = true) String bizType,
            // 原始业务请求单号。如对某一次退款进行履约时，该字段传退款时的退款请求号
            @ApiParam(value = "原始业务请求单号", defaultValue = "2014112611001004680073956707") @RequestParam(required = false)
            String origRequestNo,
            // 商户传入同步信息，具体值要和支付宝约定；
            // 用于芝麻信用租车、单次授权等信息同步场景，格式为json格式。 状态枚举如下：
            // COMPLETE：同步用户已履约 适用场景：发起扣款后，芝麻生成待履约记录，如果用户通过其他方式完成订单支付，请反馈该状态，芝麻将完结待履约记录对用户形成一条良好履约记录；同步该状态时需要同步调用 取消扣款 接口关闭交易订单。
            // CLOSED： 同步履约已取消 适用场景：发起扣款后，芝麻生成待履约记录，如果发现该笔扣款无效需要取消，请反馈该状态，芝麻将取消用户待履约记录；同步该状态时需要同步调用 取消扣款 接口关闭交易订单。
            @ApiParam(value = "同步信息", defaultValue = "{\"status\":\"COMPLETE\"}") @RequestParam(required = false) String orderBizInfo) {
        return depositOrderManageService.syncOrder(tradeNo, outRequestNo, bizType, origRequestNo, orderBizInfo);
    }
}